/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function Department() {
    this.javaClass = "org.workforce.core.Department";
    this.id = "";
    this.name = "";
    this.description = "";
}

function mainDepartment() {
    var body = document.getElementById("_body");
    body.innerHTML = requestPage("Department.main.jsp");
    body.style.visibility = "visible";
}
function addDepartment() {
    var department = new Department();
    department.id = "";
    department.name = document.getElementById("department_pre_name").value;
    department.description = document.getElementById("department_pre_description").value;
    var chk = serviceLocator.saveDepartment(department);
    if( chk == "true" ) {
        alert("Add Department Complete.");
    } else {
        alert("Cann't Add Department.");
    }
}
function saveDepartment() {
    loading();
    var obj = new Department();
    obj.id = document.getElementById("department_pre_id").value;
    obj.name = document.getElementById("department_pre_name").value;
    obj.description = document.getElementById("department_pre_description").value;
    var chk = serviceLocator.updateDepartment(obj);
    if( chk == "true" ) {
        alert("Update Department Complete.");
    } else {
        alert("Cann't Update Department!");
    }
    unloading();
}
function searchDepartment() {
    loading();
    var department = new Department();
    department.name = document.getElementById("departmentName").value;
    var pages = serviceLocator.pageSearchCritiriaDepartment(department);
    var ls = serviceLocator.searchCritiriaDepartment(department, 0);
    setTableHeader("departmentTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description"], pages.count, ""+pages.iterator, "searchDepartmentN");
    loadTable("id,name,description", ls, "departmentTable","delDepartment","edtDepartment");
    unloading();
}
function searchDepartmentN(offset) {
    loading();
    var department = new Department();
    department.name = document.getElementById("departmentName").value;
    var pages = serviceLocator.pageSearchCritiriaDepartment(department);
    var ls = serviceLocator.searchCritiriaDepartment(department, offset);
    setTableHeader("departmentTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description"], pages.count, ""+pages.iterator, "searchDepartmentN");
    loadTable("id,name,description", ls, "departmentTable","delDepartment","edtDepartment");
    unloading();
}
function delDepartment(id) {
    var sysConfirm = new SysConfirm();
    sysConfirm.message = "You do want delete id["+id+"]";
    sysConfirm.callOK = "department_confirm_delete_ok('"+id+"')";
    sysConfirm.confirm();
}
function department_confirm_delete_ok(id) {
    var department = new Department();
    department.id = id;
    serviceLocator.removeDepartment(department);
    searchDepartment();
}
function edtDepartment(id) {
    loading();
    var department = new Department();
    department.id = id;
    var departmentEdit = serviceLocator.findDepartment(department);
    actionForward('_body','Department.form.jsp');
    document.getElementById("department_pre_id").value = departmentEdit.id;
    document.getElementById("department_pre_name").value = departmentEdit.name;
    document.getElementById("department_pre_description").value = departmentEdit.description;
    document.getElementById("department_pre_save").setAttribute("onclick", "saveDepartment()");
    unloading();
}
function departmentClear() {
    document.getElementById("departmentName").value = "";
}



